/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vue;

import Modele.SolverV2;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;

/**
 *
 * @author Gloire
 */
public class Fenetre extends JFrame{
    

    private Essai essai;
    private Accueil accueil;
    private Score score;
    private SolverV2 sol;
    
    private JLabel jchrono;
    private JLabel jscore;
    
    private JMenuBar bar;
    
    private Resultat r;
    
    private Score s;
    
    public Essai getEssai(){
        return essai;
    }
    
    public Score getScore(){
        return s;
    }
    public Fenetre(){
        int chrono = 90; 
        jchrono = new JLabel("Chrono : " + chrono);
        essai = new Essai(jchrono,chrono,this);
        time(chrono);
        
        setContentPane(essai);
        s = new Score(essai.getTrouves());
        essai.setScore(s);
        add("West",s);
        bar = new JMenuBar();        
        bar.add(Box.createHorizontalStrut(10));
        bar.add(jchrono);
        
        setJMenuBar(bar);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(true);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
        sol = new SolverV2(essai.getGrille().getGrille(),essai.getDico());
        essai.setSolutions(sol.getResult());
        r = new Resultat(sol.getResult());
    }
    
    public static ImageIcon createIcon(String path, String desc) {
		try {
			return new ImageIcon(ImageIO.read(new File("./src/images/"+ path)), desc);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
    }
    
    public void time(int i){
        new java.util.Timer().schedule(new java.util.TimerTask() {
			@Override
			public void run() {
				changeToScores();
			}
        }, 1000 * i);
    }
    
    public void changeToScores(){
        essai.add(r);
        setContentPane(essai);
    }
}
